<?php

declare(strict_types=1);

namespace App\Model\Framework;

use App\Model\Model;

class AdminSetupModel extends Model
{
    /**
     * The table associated with the model.
     *
     * @var ?string
     */
    protected ?string $table = 'admin_setup';

    protected ?string $dateFormat = 'U';

    /**
     * 默认查询字段
     *
     * @var array|string[]
     */
    public array $select = [
        'id', 'name', 'table', 'value'
    ];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->is_delete_search = 0;
        $this->is_status_search = 0;
    }

    public function searchTableAttribute($query, $value, array $params): mixed
    {
        if (empty($value)) {
            return $query;
        }
        return $query->where('table', $value);
    }

    public function dataValueAttribute($value,$params)
    {
        $value = !empty($value) ? $value : '{}';
        return json_decode($value,true);
    }
}
